package com.gs.spring.util.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import com.gs.spring.core.domain.Patient;
import com.gs.spring.core.domain.Person;
import com.gs.spring.core.domain.Visit;
import com.gs.spring.core.domain.factory.PatientFactory;
import com.gs.spring.core.service.PatientService;
import com.gs.spring.util.service.PatientUtilService;

@Service(value="patientUtilService")
public class PatientUtilServiceImpl implements PatientUtilService, InitializingBean {
	
	static Map<Long, Patient> patients = new HashMap<Long, Patient>();
	
	@Autowired
	PatientFactory patientFactory;
	
	public void initPatients(){
		
		Patient patient = null;
		for (int i = 0; i < 10; i++) {
			//patient = getPatient();
			try {
				patient = patientFactory.getObject();
			} catch (Exception e) {
				e.printStackTrace();
			}
			patient.setVisits(new ArrayList<Visit>());
			patients.put(patient.getId(), patient);
		}
	}
	

	
	public Collection<Patient> findAll(){
		return patients.values();
	}
	public Patient findOne(Long id){
		return patients.get(id);
	}

	public void afterPropertiesSet() throws Exception {
		initPatients();		
	}



	public Patient savePatient(Patient patient) {
		System.out.println("Save patient");
		return patient;
	}
}
